package com.cx.mall.demo.controller;

import com.cx.mall.common.util.ResponseVO;
import com.cx.mall.demo.entity.Dog;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

@RestController
@RequestMapping("/param")
public class ParamController {
    @GetMapping("/get")
    public ResponseVO<String> getParam(String name, Integer age, String sex) {
        String s =  "name:" + name + " age:" + age + " sex:" + sex;
        return ResponseVO.success(s);
    }
    @GetMapping("/getObj")
    public ResponseVO<Dog> getObj(Dog dog){
        return ResponseVO.success(dog);
    }
    @GetMapping("/getArray")
    public String getArrayParam(
            String name,
            @RequestParam(value = "love") String[] loves){
        return "{name:" + name +",loves:" + Arrays.stream(loves).toList() + "}";
    }
    @PostMapping("/postObject")
    public Dog postJson(@RequestBody Dog dog){
        return dog;
    }

    @PostMapping("/postJson")
    public ResponseVO<List<Dog>> postObj(@RequestBody List<Dog> dogs){
        return ResponseVO.success(dogs);
    }
    @GetMapping("/getUser/{id}")
    public String getUser(@PathVariable Integer id){
        return "user:" + id;
    }

}
